<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" name="name" id="Num" placeholder="请输入要计算数字:" />
    <input value="杨辉三角" type="button" onclick="generatePascal();" />
    <script type="text/javascript">
        function Combination(m, n) {
            if (n === 0 || m === n) {
                return 1;
            }
            return Combination(m - 1, n - 1) + Combination(m - 1, n);
        }

        function Pascal(rows) {
            for (let i = 0; i < rows; i++) {
                let row = '';
                for (let j = 0; j <= i; j++) {
                    row += Combination(i, j) + ' ';
                }
                console.log(row);
            }
        }

        function generatePascal() {
            const inputElement = document.getElementById('Num');
            const rows = parseInt(inputElement.value, 10);
            if (isNaN(rows) || rows <= 0) {
                alert('请输入一个有效的正整数');
                return;
            }
            Pascal(rows);
        }
    </script>
    </script>
</body>
</html>